package com.sc.nft.dao;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.EcologyPoolRelationConditionBind;
import com.sc.nft.enums.EcologyPoolRelationConditionBindTypeEnum;
import com.sc.nft.enums.EcologyPoolRelationTypeEnum;
import com.sc.nft.mapper.EcologyPoolRelationConditionBindMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author 刘国航
 * @since 2024/8/10 16:20
 */
@Slf4j
@Repository
public class EcologyPoolRelationConditionBindDao extends ServiceImpl<EcologyPoolRelationConditionBindMapper, EcologyPoolRelationConditionBind> {


    public int saveRedPackNftBind(List<EcologyPoolRelationConditionBind> ecologyPoolRedPackRelationDTOS) {
        return baseMapper.saveRedPackNftBind(ecologyPoolRedPackRelationDTOS);
    }

    public List<EcologyPoolRelationConditionBind> getListByBind(Long bindId, EcologyPoolRelationConditionBindTypeEnum ecologyPoolRelationConditionBindTypeEnum, EcologyPoolRelationTypeEnum ecologyPoolRelationTypeEnum) {
        if (Objects.isNull(bindId)) {
            return new ArrayList<>();
        }
        LambdaUpdateWrapper<EcologyPoolRelationConditionBind> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyPoolRelationConditionBind::getBindId, bindId);
        wrapper.eq(EcologyPoolRelationConditionBind::getBindType, ecologyPoolRelationConditionBindTypeEnum);
        wrapper.eq(Objects.nonNull(ecologyPoolRelationTypeEnum), EcologyPoolRelationConditionBind::getRelationType, ecologyPoolRelationTypeEnum);
        return list(wrapper);
    }

    public List<EcologyPoolRelationConditionBind> getListByBinds(List<Long> bindIdList, EcologyPoolRelationConditionBindTypeEnum ecologyPoolRelationConditionBindTypeEnum, EcologyPoolRelationTypeEnum ecologyPoolRelationTypeEnum) {
        if (CollectionUtil.isEmpty(bindIdList)) {
            return new ArrayList<>();
        }
        LambdaUpdateWrapper<EcologyPoolRelationConditionBind> wrapper = new LambdaUpdateWrapper<>();
        wrapper.in(EcologyPoolRelationConditionBind::getBindId, bindIdList);
        wrapper.eq(EcologyPoolRelationConditionBind::getBindType, ecologyPoolRelationConditionBindTypeEnum);
        wrapper.eq(Objects.nonNull(ecologyPoolRelationTypeEnum), EcologyPoolRelationConditionBind::getRelationType, ecologyPoolRelationTypeEnum);
        return list(wrapper);
    }

}
